package com.briup.jz.service.impl;

import java.util.List;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.jz.dao.BaseFileMapper;
import com.briup.jz.bean.BaseFile;
import com.briup.jz.bean.BaseFileExample;

import com.briup.jz.service.IBaseFileService;
import com.briup.jz.utils.CustomerException;
@Service
public class BaseFileServiceImpl implements IBaseFileService{

	@Autowired
	private BaseFileMapper basefileMapper;

	/*@Override
	public void saveOrUpdate(BaseFile basefile) {
		// TODO Auto-generated method stub
		if(basefile.getId()!=null) {
			basefileMapper.updateByPrimaryKey(basefile);
		} else {
			// 判断是否有同名的分类，如果有抛出异常
			BaseFileExample example = new BaseFileExample();
			example.createCriteria().andFileNameEqualTo(basefile.getFileName());
			List<BaseFile> list = basefileMapper.selectByExample(example);
			if(list.size()>0) {
				throw new CustomerException("同名的分类已存在");
			}
			basefileMapper.insert(basefile);
		}
		
	}*/

	@Override
	public List<BaseFile> query(String name) {
		// TODO Auto-generated method stub
		BaseFileExample example = new BaseFileExample();
		if(name!=null){
			example.createCriteria().andFileNameLike("%"+name+"%");
		}
		List<BaseFile> list = basefileMapper.selectByExample(example);
		return list;
	 }
	@Override
	public void deleteById(String id) throws CustomerException {
		
		//BaseFile basefile = basefileMapper.selectByPrimaryKey(id);
		BaseFile basefile =basefileMapper.selectByPrimaryKey(id);
		if(basefile == null) {
			throw new CustomerException("要删除的分类信息不存在");
		}
		basefileMapper.deleteByPrimaryKey(id);
		
	}

}